package com.datastructure.practice.t1;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;

public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.numDistinct("nowccower","nowccower");
    }

    class A {
        A(String f){

        }
    }
    class B extends A{
        B(){
            super("");

        }
    }
    /**
     *
     * @param S string字符串
     * @param T string字符串
     * @return int整型
     */
    public int numDistinct (String S, String T) {
        // write code here
        int sum=0;
        boolean flag=false;
        ArrayList<ArrayList<Byte>> subsets = subsets(S.getBytes());
        ArrayList<ArrayList<Byte>> subsets1 = subsets(T.getBytes());
        for (ArrayList<Byte> subset : subsets) {
            for (ArrayList<Byte> list : subsets1) {
                if(subset.size()== list.size()){
                    for (int i = 0; i < subset.size(); i++) {
                        if(!subset.get(i).equals(list.get(i))){
                            flag=true;
                        }
                    }
                    if(flag){
                        sum++;
                    }
                    flag=false;
                }
            }
        }
        return sum;
    }
    public ArrayList<ArrayList<Byte>> subsets(byte[] S) {
        ArrayList<ArrayList<Byte>> lists = new ArrayList<ArrayList<Byte>>();
        // 总结果数 2的n次方
        int count = 1 << S.length;
        for (int i = 0; i < count; i++) {
            ArrayList<Byte> list = new ArrayList<>();
            // j位置要么是true选中，要么是false不选
            // 这里其实就是想判断，将i转成二进制之后，从右往左数第j+1位是不是1
            for (int j = 0; j < S.length; j++) {
                if ((1 << j & i) != 0) {
                    list.add(S[j]);
                }
            }

            lists.add(list);
        }
        return lists;
    }

    public ArrayList<String> subsets1(String A) {
        ArrayList<String> lists = new ArrayList<String>();
        // 总结果数 2的n次方
        int count = 1 << A.length();
        for (int i = 0; i < count; i++) {
            StringBuilder list = new StringBuilder("");
            // j位置要么是true选中，要么是false不选
            // 这里其实就是想判断，将i转成二进制之后，从右往左数第j+1位是不是1
            for (int j = 0; j < A.length(); j++) {
                if ((1 << j & i) != 0) {
                    list.append(String.valueOf(A.indexOf(j)));
                }
            }
            if(list.length()==3){
                lists.add(list.toString());
            }

        }
        return lists;
    }
}
